package org.cadet.client.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cadet.client.bean.BeanThought;
import org.cadet.client.model.ThoughtManagement;

/**
 * @author Nagmani
 *
 */

public class ThoughtServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ThoughtServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		try {
			ArrayList<BeanThought> thoughts = null;
			ThoughtManagement objThoughtManagement = new ThoughtManagement();
			String status = "";
			try{
				thoughts = objThoughtManagement.viewAllThought();
				status = "success";
			}
			catch(Exception e){
				status = "fail";
			}
			request.setAttribute("status", status);
			request.setAttribute("thoughts", thoughts);
			RequestDispatcher rd = request.getRequestDispatcher("/client/thought.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			out.close();
		}
		//response.sendError(403, "No Get Request Allowed for this Page");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
